package bing.json;

import java.io.IOException;
import java.util.Iterator;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ParseJsonStr {

	public static void main(String[] args) throws IOException {
		String jsonStr="{\"name\": {\"type\": \"string\", \"analyzer\": \"ik_smart\"},\"age\": {\"type\": \"long\", \"analyzer\": \"ik_smart\"}}";
		ObjectMapper mapper=new ObjectMapper();
		JsonNode topNode=mapper.readTree(jsonStr);
		Iterator<String> topFields = topNode.fieldNames();
		
		/*while(fields.hasNext()) {
			System.out.println(fields.next());
		}*/
		
		while(topFields.hasNext()) {
			String fieldName=topFields.next();
			System.out.println(fieldName);
			JsonNode node = topNode.get(fieldName);
			//System.out.println(node);
			
			Iterator<String> tmp=node.fieldNames();
			while(tmp.hasNext()) {
				String tp=tmp.next();
				System.out.println(tp+" : "+node.get(tp).asText());
			}
		}
		
	}
}
